package com.lz.dao;

import com.lz.beans.AppUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * Created by lz on 2018/5/10.
 */
@Repository
public class RegisterDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    /**
     * 注册
     *
     * @param appUser
     */
    public int register(AppUser appUser) throws Exception {

        String sql = "insert into t_user " +
                " (username,password,tel,sex,identitycard,familyid,usertype,comment) " +
                " values (?,?,?,?,?,?,?,?)";
        return jdbcTemplate.update(sql, appUser.getUsername(),
                appUser.getPassword(), appUser.getTel(), appUser.getSex(), appUser.getIdentitycard(),
                appUser.getFamilyid(),appUser.getUsertype(),appUser.getComment());
    }

    /**
     * 修改密码
     *
     * @param password
     * @param id
     * @return
     * @throws Exception
     */
    public int modifyPassword(String password, Object id) throws Exception {
        String sql = "update t_user set password = ? where id = ?";
        return jdbcTemplate.update(sql, password, id);
    }

    /**
     * 修改其他信息
     * @param appUser
     * @param id
     * @return
     * @throws Exception
     */
    public int modifyInfo(AppUser appUser, Object id) throws Exception{
        String sql = "update t_user set " +
                " tel = ? , sex = ? , identitycard = ? , familyid = ? , usertype = ? , comment = ?" +
                "where id = ?";
        return jdbcTemplate.update(sql, appUser.getTel(),appUser.getSex(),
                appUser.getIdentitycard(),appUser.getFamilyid(),appUser.getUsertype(),appUser.getComment(),id);
    }
}
